{{ trigger.call("before_post_fields", feather) }}
{% for field in feather.fields %}
{% if attribute(post, field.attr) is defined %}
{% set field_value = attribute(post, field.attr) %}
{% else %}
{% set field_value = field.value is defined ? field.value : "" %}
{% endif %}
{% set field_count = field_value is iterable ? field_value | length : 1 %}
{% set field_preview = field.preview is defined and field.preview ? ' data-preview="feather:' ~ (feather.safename | fix(true)) ~ '"' : "" %}
{% set field_multiple = field.multiple is defined and field.multiple ? " multiple" : "" %}
{% set field_accept = field.accept is defined ? ' accept="' ~ (field.accept | fix(true)) ~ '"' : "" %}
{% if site.enable_markdown %}
{% set field_markdown = field.filters is defined and (field.filters | contains("markup_text")) ? " data-markdown" : "" %}
{% else %}
{% set field_markdown = "" %}
{% endif %}
{% if post is not defined %}
{% set field_required = field.optional is defined and field.optional ? "" : " required" %}
{% else %}
{% set field_required = field.type == "file" or field.optional is defined and field.optional ? "" : " required" %}
{% endif %}
{% set field_id = (field.attr ~ "_field") | fix(true) %}
{% set field_name = (field_multiple is not empty ? field.attr ~ "[]" : field.attr) | fix(true) %}
<p class="main_options">
<label for="{{ field_id }}">
{{ field.label }}
{% if field.note is defined %}
{{ field.note }}
{% endif %}
{% if field.help is defined %}
<a href="{{ url('help/id/' ~ (field.help | url_encode)) }}" rel="help" target="_blank" class="help emblem">
{{- icon_svg("help.svg", "Help" | translate) -}}
</a>
{% endif %}
</label>
{% if field.type == "text" %}
<input id="{{ field_id }}" class="text" type="text" name="{{ field_name }}"{{ field_markdown ~ field_required }} value="{{ field_value | fix(true, true) }}">
{% elseif field.type == "url" %}
<input id="{{ field_id }}" class="text" type="url" name="{{ field_name }}"{{ field_required }} value="{{ field_value | fix(true, true) }}">
{% elseif field.type == "email" %}
<input id="{{ field_id }}" class="text" type="email" name="{{ field_name }}"{{ field_required }} value="{{ field_value | fix(true, true) }}">
{% elseif field.type == "file" %}
<span id="{{ field_id }}_toolbar" class="options_toolbar file_toolbar" role="toolbar"></span>
{%- if visitor.group.can("add_upload") -%}
<input id="{{ field_id }}" type="file" name="{{ field_name }}"{{ field_accept ~ field_multiple ~ field_required }} value="" data-file_list="{{ (field_value is iterable ? field_value | join(', ') : field_value) | fix(true) }}">
{%- else -%}
<input id="{{ field_id }}" class="text" type="text" name="{{ field.attr }}"{{ field_accept ~ field_multiple ~ field_required }} pattern="{{ field_multiple ? '^([a-z0-9\\-\\.](, *)?)*$' : '^[a-z0-9\\-\\.]*$' }}" value="" data-file_list="{{ (field_value is iterable ? field_value | join(', ') : field_value) | fix(true) }}">
<span id="{{ field_id }}_tray" class="options_tray" role="status">
{{ "You do not have sufficient privileges to add uploads." | translate("chyrp") }}
</span>
{%- endif -%}
{% elseif field.type == "text_block" %}
<span id="{{ field_id }}_toolbar" class="options_toolbar text_block_toolbar" role="toolbar">
{%- if field_markdown is not empty -%}
<a href="{{ url('help/id/markdown') }}" target="_blank" class="help emblem markdown">
{{- icon_svg("markdown.svg", "Markdown" | translate) -}}
</a>
{%- endif -%}
</span>
<textarea id="{{ field_id }}" name="{{ field_name }}" rows="10"{{ field_preview ~ field_markdown ~ field_required }}>{{ field_value | fix(false, true) }}</textarea>
<span id="{{ field_id }}_tray" class="options_tray" role="status"></span>
{% elseif field.type == "checkbox" %}
<input id="{{ field_id }}" type="checkbox" name="{{ field_name }}"{{ field_value | checked }}>
{% elseif field.type == "select" %}
<select id="{{ field_id }}" name="{{ field_name }}">
{% for value, name in field.options %}
<option value="{{ value | fix(true) }}"{{ field_value | selected(value) }}>
{{ name | fix }}
</option>
{% endfor %}
</select>
{% endif %}
{% if field.extra is defined %}
{{ field.extra }}
{% endif %}
</p>
{% endfor %}
{{ trigger.call("after_post_fields", feather) }}
<div id="more_options" class="more_options">
{% if visitor.group.can("add_post") %}
<p class="more_options_option">
<label for="status">{{ "Status" | translate }}</label>
<select id="status" name="status">
{% set post_status = post is defined ? post.status : site.default_post_status %}
{% set status_constant = constant("Post::STATUS_DRAFT") %}
<option value="{{ status_constant }}"{{ status_constant | selected(post_status) }}>
{{ "Draft" | translate }}
</option>
{% set status_constant = constant("Post::STATUS_PUBLIC") %}
<option value="{{ status_constant }}"{{ status_constant | selected(post_status) }}>
{{ "Public" | translate }}
</option>
{% set status_constant = constant("Post::STATUS_PRIVATE") %}
<option value="{{ status_constant }}"{{ status_constant | selected(post_status) }}>
{{ "Private" | translate }}
</option>
{% set status_constant = constant("Post::STATUS_SCHEDULED") %}
<option value="{{ status_constant }}"{{ status_constant | selected(post_status) }}>
{{ "Scheduled" | translate }}
</option>
<optgroup label="{{ 'Visible only to a group of users:' | translate }}">
{% set status_constant = constant("Post::STATUS_REG_ONLY") %}
<option value="{{ status_constant }}"{{ status_constant | selected(post_status) }}>
{{ "All registered users" | translate }}
</option>
{% if groups is not empty %}
{% for group in groups %}
{% set group_id = "{" ~ group.id ~ "}" %}
<option value="{{ group_id }}"{{ group_id | selected(post_status) }}>
{{ group.name | fix(false, true) }}
</option>
{% endfor %}
{% endif %}
</optgroup>
</select>
</p>
{% endif %}
<p class="more_options_option">
<label for="pinned">
{{ "Pinned?" | translate }}
{{ "(shows this post above all others)" | translate }}
</label>
<input id="pinned" type="checkbox" name="pinned"{{ (post is defined ? post.pinned : false) | checked }}>
</p>
<p class="more_options_option">
<label for="slug">
{{ "Slug" | translate }}
<a href="{{ url('help/id/slugs') }}" rel="help" target="_blank" class="help emblem">
{{- icon_svg("help.svg", "Help" | translate) -}}
</a>
</label>
<input id="slug" class="text" type="text" name="slug" value="{{ post is defined ? post.clean | fix(true) : '' }}" maxlength="128"{{ slug_pattern() }}>
</p>
<p class="more_options_option">
<label for="created_at">{{ "Timestamp" | translate }}</label>
{% set post_created = post is defined and post.status != "draft" ? post.created_at : now %}
<input id="created_at" class="text" type="text" name="created_at" value="{{ post_created | dateformat('Y-m-d H:i:s') | fix(true) }}">
</p>
{% for field in options %}
{% set field_value = field.value is defined ? field.value : "" %}
{% set field_multiple = field.multiple is defined and field.multiple ? " multiple" : "" %}
{% set field_accept = field.accept is defined ? ' accept="' ~ (field.accept | fix(true)) ~ '"' : "" %}
{% set field_id = ((field.attr | replace({"[": "_", "]": ''})) ~ "_field") | fix(true) %}
{% set field_name = (field_multiple is not empty ? field.attr ~ "[]" : field.attr) | fix(true) %}
<p class="more_options_option">
<label for="{{ field_id }}">
{{ field.label }}
{% if field.note is defined %}
{{ field.note }}
{% endif %}
{% if field.help is defined %}
<a href="{{ url('help/id/' ~ (field.help | url_encode)) }}" rel="help" target="_blank" class="help emblem">
{{- icon_svg("help.svg", "Help" | translate) -}}
</a>
{% endif %}
</label>
{% if field.type == "text" %}
<input id="{{ field_id }}" class="text" type="text" name="{{ field_name }}" value="{{ field_value | fix(true, true) }}">
{% elseif field.type == "url" %}
<input id="{{ field_id }}" class="text" type="url" name="{{ field_name }}" value="{{ field_value | fix(true, true) }}">
{% elseif field.type == "email" %}
<input id="{{ field_id }}" class="text" type="email" name="{{ field_name }}" value="{{ field_value | fix(true, true) }}">
{% elseif field.type == "file" %}
<input id="{{ field_id }}" type="file" name="{{ field_name }}"{{ field_accept ~ field_multiple }} value="">
{% elseif field.type == "text_block" %}
<textarea id="{{ field_id }}" name="{{ field_name }}" rows="10">{{ field_value | fix(false, true) }}</textarea>
{% elseif field.type == "checkbox" %}
<input id="{{ field_id }}" type="checkbox" name="{{ field_name }}"{{ field_value | checked }}>
{% elseif field.type == "select" %}
<select id="{{ field_id }}" name="{{ field_name }}">
{% for option in field.options %}
<option value="{{ option.value | fix(true) }}"{{ option.selected | selected(true) }}>
{{ option.name | fix }}
</option>
{% endfor %}
</select>
{% endif %}
{% if field.extra is defined %}
{{ field.extra }}
{% endif %}
</p>
{% endfor %}
</div>
<div class="buttons confirmation">
{% if route.action == "edit_post" %}
{% if visitor.group.can("add_post") and post.status == "draft" %}
<button type="submit" class="yay" name="publish" value="true">
{{ "Publish" | translate }}
</button>
<button type="submit">
{{ "Save" | translate }}
</button>
{% else %}
<button type="submit">
{{ "Save" | translate }}
</button>
<button type="submit" class="boo" name="cancel" value="true" data-confirm="">
{{ "Cancel" | translate }}
</button>
{% endif %}
{% else %}
{% if visitor.group.can("add_post") %}
<button type="submit" class="yay">
{{ "Publish" | translate }}
</button>
{% endif %}
<button type="submit" name="draft" value="true">
{{ "Save" | translate }}
</button>
{% endif %}
</div>
